{extend name='common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
	<div class="ibox-content">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row">
				<div class="col-sm-12">
					<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">等级名称：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="name"   name="name" class="form-control" placeholder="请输入等级名称"  >
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">自动升级上传个数：</label>
						<div class="col-sm-9">
							<input type="number" autocomplete="off" id="up_num"   name="name" class="form-control" placeholder="请输入数量"  >
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">有效期：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="expiry"   name="work_years" class="form-control" placeholder="请输入有效期"  >
						</div>
					</div>

					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">有效期单位：</label>
						<div class="col-sm-9">
							<input name="unit" value="1" type="radio" checked  title="月">
							<input name="unit" value="2" type="radio" title="年">
						</div>
					</div>

					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">状态：</label>
						<div class="col-sm-9">
							<input name="status" value="1" type="radio" checked  title="开启">
							<input name="status" value="0" type="radio"    title="关闭">
						</div>
					</div>

					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">招商代理：</label>
						<div class="col-sm-9">
							<input  lay-filter="radioFilter"   name="is_zs" value="1" type="radio"     title="是">
							<input  lay-filter="radioFilter"  name="is_zs" value="0" type="radio"  checked  title="否">
						</div>
					</div>

					<div class="form-group"  id="zs_price_div" style="display: none">
						<label class="col-sm-2 control-label">加盟费用：</label>
						<div class="col-sm-9">
							<input type="number" autocomplete="off" id="zs_price"      name="zs_price" class="form-control" placeholder="请输入金额"  >
						</div>
					</div>

					<!-- form end -->
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.add()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/upload.js" charset="utf-8"></script>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>
	layui.use(['form'],function(){

		var form = layui.form;

		// 绑定radio的click事件
		form.on('radio(radioFilter)', function(data){
			// data是一个包含当前radio的所有数据的对象
			var is_zs_val=data.value;
			if(is_zs_val==0){
				$("#zs_price_div").hide();
			}else{
				$("#zs_price_div").show();
			}
			console.log(data.value); // 被点击的radio的value值
			console.log(data.title); // 被点击的radio的显示文本
			// 在这里编写你的逻辑代码
		});
	});
	laydate.render({elem: '#createtime',type: 'datetime',trigger:'click'});
	laydate.render({elem: '#expiretime',type: 'datetime',trigger:'click'});
	var CodeInfoDlg = {
		CodeInfoData: {},
		validateFields: {
			status: {
				validators: {
					notEmpty: {
						message: '状态不能为空'
					},
				}
			},
		}
	}

	CodeInfoDlg.collectData = function () {
		this.set('name').set('expiry').set('up_num').set('zs_price');
	};

	CodeInfoDlg.update = function () {
		this.clearData();
		this.collectData();
		if (!this.validate()) {
			return;
		}
		var unit = $("input[name = 'unit']:checked").val();
		var is_zs=$("input[name = 'is_zs']:checked").val();
		var status = $("input[name = 'status']:checked").val();
		var ajax = new $ax(Feng.ctxPath + "/ZhMatchmakerLevel/update", function (data) {
			if ('00' === data.status) {
				Feng.success(data.msg,1000);
				window.parent.CodeGoods.table.refresh();
				CodeInfoDlg.close();
			} else {
				Feng.error(data.msg + "！",1000);
			}
		})
		ajax.set('unit',unit);
		ajax.set('status',status);
		ajax.set('is_zs',is_zs);
		ajax.set(this.CodeInfoData);
		ajax.start();
	};


	CodeInfoDlg.add = function () {
		this.clearData();
		this.collectData();
		if (!this.validate()) {
			return;
		}
		var unit = $("input[name = 'unit']:checked").val();
		var status = $("input[name = 'status']:checked").val();
		var ajax = new $ax(Feng.ctxPath + "/ZhMatchmakerLevel/add", function (data) {
			if ('00' === data.status) {
				Feng.success(data.msg,1000);
				window.parent.CodeGoods.table.refresh();
				CodeInfoDlg.close();
			} else {
				Feng.error(data.msg + "！",1000);
			}
		})
		ajax.set('status',status);
        ajax.set('unit',unit);
		ajax.set(this.CodeInfoData);
		ajax.start();
	};

</script>
<script src="__PUBLIC__/static/js/base.js" charset="utf-8"></script>
{/block}
